const { ipcRenderer } = require('electron');
const editor = document.getElementById('editor');

// 监听打开文件事件
ipcRenderer.on('open-file', (event, text) => {
    editor.value = text;
});

// 监听保存文件事件
ipcRenderer.on('save-file', async () => {
    const text = editor.value;
    const { canceled, filePath } = await dialog.showSaveDialog({
        filters: [
            { name: '文本文件', extensions: ['txt'] }
        ]
    });
    if (!canceled) {
        const { writeFileSync } = require('fs');
        writeFileSync(filePath, text);
        alert('文件已保存');
    }
});